#include <stdio.h>
#include <stdlib.h>

// 函数声明
int countdigit(int number, int digit);

int main(void)
{
    int number, digit;
    scanf("%d%d", &number, &digit);
    printf("%d\n", countdigit(number, digit));
    return 0;
}

// 函数定义
int countdigit(int number, int digit)
{
    int count = 0;
    if (number == 0 && digit == 0) return 1;
    number = abs(number); // 处理负数
    while (number != 0) {
        if (number % 10 == digit)
            count++;
        number /= 10;
    }
    return count;
}